package com.bamboo.msmservice.controller;

import com.bamboo.commonutils.ResponseEntity;
import com.bamboo.msmservice.service.MsmService;
import com.bamboo.servicebase.exceptionhandler.BambooException;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author jack.wu
 * @version 1.0
 * @date 2020-07-13
 */
@RestController
@RequestMapping("/edumsm/msm")
public class MsmController {

    @Resource
    private MsmService msmService;

    @GetMapping("/send/{phone}")
    public ResponseEntity sendMsm(@PathVariable String phone) {
        if (StringUtils.isEmpty(phone)) {
            throw new BambooException(20001, "请输入手机号在点击发送");
        }
        boolean isSuccess = msmService.sendMsm(phone);
        if (isSuccess) {
            return ResponseEntity.ok();
        } else {
            return ResponseEntity.error().message("验证码发送失败");
        }

    }
}
